package Bean;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletConfig;

public class Database {
	
	final private String strDriverName = "com.mysql.jdbc.Driver";
	final private String strUserName = "javauser";
	final private String strPassword = "javadude";
	final private String strDriverUrl = "jdbc:mysql://localhost:3306/mydb";

	private Connection mConn = null;
	protected Statement mStmt = null;
	protected ResultSet mRs = null;

	public Database() {

		try {
			Class.forName(strDriverName);
			mConn = DriverManager.getConnection(strDriverUrl, strUserName, strPassword);
			mStmt = mConn.createStatement();
		} catch (SQLException | ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	public void closeDB() {
		try {
			if (mRs != null) {
				mRs.close();
			}

			if (mStmt != null) {
				mStmt.close();
			}
			
			if (mConn != null) {
				mConn.close();
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
